<?php
namespace app\driving\controller;

use think\Db;

class Question
{
    public function getQuestionList()
    {
    	$type = input('type');
    	$data['question_list_1'] = Db::name('driving_test')->where('type',$type)->where('subject',1)->select();
    	$data['question_list_4'] = Db::name('driving_test')->where('type',$type)->where('subject',4)->select();    
      
    	return $data;
	}

	public function getTestList(){
		$type    = input('type');
		$subject = input('subject');
		if($subject == 1){
			//从数据库随机获取40道判断题
		    $data['test_list_1'] = Db::name('driving_test')->where('type',$type)->where('subject',$subject)->where('question_types',2)->orderRaw('rand()')->limit(40)->select();
		    //从数据库随机获取60道选择题
		    $data['test_list_2'] = Db::name('driving_test')->where('type',$type)->where('subject',$subject)->where('question_types',1)->orderRaw('rand()')->limit(60)->select();
		    $test_list = array_merge($data['test_list_1'],$data['test_list_2']);
		}

		if($subject == 4){
			//从数据库随机获取40道判断题
		    $data['test_list_1'] = Db::name('driving_test')->where('type',$type)->where('subject',$subject)->where('question_types',2)->orderRaw('rand()')->limit(20)->select();
		    //从数据库随机获取60道选择题
		    $data['test_list_2'] = Db::name('driving_test')->where('type',$type)->where('subject',$subject)->where('question_types',1)->orderRaw('rand()')->limit(20)->select();
		      //从数据库随机获取60道选择题
		    $data['test_list_3'] = Db::name('driving_test')->where('type',$type)->where('subject',$subject)->where('question_types',3)->orderRaw('rand()')->limit(10)->select();
		    $test_list = array_merge($data['test_list_1'],$data['test_list_2']);
		    $test_list = array_merge($test_list,$data['test_list_3']);
		}
		
		return $test_list;
	}
}